<?php

namespace app\model\activity\free;

use app\model\product\product\StoreProduct;
use app\model\product\sku\StoreProductAttrValue;
use crmeb\basic\BaseModel;
use crmeb\traits\ModelTrait;

class FreeRuleProduct extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'free_rule_products';

    use ModelTrait;

    public function freeRule()
    {
        return $this->belongsTo(StoreFreeRule::class, 'free_rule_id', 'id');
    }


    public function product()
    {
        return $this->belongsTo(StoreProduct::class, 'product_id', 'id')->where('is_del', 0);
    }

    /**
     * 一对一关联
     * 购物车关联商品商品规格
     * @return \think\model\relation\HasOne
     */
    public function attrInfo()
    {
        return $this->hasOne(StoreProductAttrValue::class, 'unique', 'product_attr_value_unique');
    }

}